package com.jianyun.jyzs.widget;

import android.app.AlertDialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;


import com.jianyun.jyzs.R;

import static io.rong.imkit.utilities.RongUtils.getScreenWidth;


/**
 * Created by mlli on 2017/11/1.
 */

public class EngineerAttDialog extends AlertDialog{
    private Context mContext;
    public interface OnDialogItemClickListener{
        void onItemClick(int index);
    }


    private OnDialogItemClickListener listener;

    public void setListener(OnDialogItemClickListener listener) {
        this.listener = listener;
    }

    public static EngineerAttDialog getInstance(Context context){
        return new EngineerAttDialog(context);
    }


    protected EngineerAttDialog(Context context) {
        super(context);
        this.mContext = context;
    }

    @Override
    protected void onStart() {
        super.onStart();
        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        final View view = inflater.inflate(R.layout.engineer_att_menu, null);
        setContentView(view);
        view.findViewById(R.id.gallery).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (listener!=null)listener.onItemClick(0);
                dismiss();
            }
        });
        view.findViewById(R.id.camera).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (listener!=null)listener.onItemClick(1);
                dismiss();
            }
        });
        view.findViewById(R.id.audio).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (listener!=null)listener.onItemClick(2);
                dismiss();
            }
        });
        view.findViewById(R.id.video).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (listener!=null)listener.onItemClick(3);
                dismiss();
            }
        });
        WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
        layoutParams.width = gePopupWidth();
        layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        getWindow().setAttributes(layoutParams);
    }
    private int gePopupWidth() {
        return getScreenWidth() - 2 * 140;
    }
}
